﻿namespace System
{
    using System.Globalization;
    using Legend;

    /// <summary>
    /// Provides extension methods for classes in the .net framework System-namespace.
    /// </summary>
    public static class SystemExtensions
    {
        /// <summary>
        /// Replaces the format item in a specified System.String with the text equivalent
        /// of the value of a corresponding System.Object instance in a specified array using
        /// invariant culture as <see cref="IFormatProvider" />.
        /// </summary>
        /// <param name="format">A composite format string.</param>
        /// <param name="arguments">An <see cref="Object" /> array containing zero or more objects to format.</param>
        /// <returns>The formatted string.</returns>
        public static string FormatInvariant(this string format, params object[] arguments)
        {
            return string.Format(format, arguments);
        }

        /// <summary>
        /// Replaces the format item in a specified System.String with the text equivalent
        /// of the value of a corresponding System.Object instance in a specified array.
        /// A specified parameter supplies culture-specific formatting information.
        /// </summary>
        /// <param name="formatProvider">An <see cref="IFormatProvider" /> that supplies culture-specific formatting information.</param>
        /// <param name="format">A composite format string.</param>
        /// <param name="arguments">An <see cref="Object" /> array containing zero or more objects to format.</param>
        /// <returns>The formatted string.</returns>
        public static string Format(this string format, IFormatProvider formatProvider, params object[] arguments)
        {
            return string.Format(formatProvider, format, arguments);
        }

        /// <summary>
        /// Replaces the format item in a specified System.String with the text equivalent
        /// of the value of a corresponding System.Object instance in a specified array using
        /// the current culture as <see cref="IFormatProvider" />.
        /// </summary>
        /// <param name="format">A composite format string.</param>
        /// <param name="arguments">An <see cref="Object" /> array containing zero or more objects to format.</param>
        /// <returns>The formatted string.</returns>
        public static string Format(this string format, params object[] arguments)
        {
            return string.Format(CultureInfo.CurrentCulture, format, arguments);
        }

        /// <summary>
        /// Gets a short string representation of the specified guid.
        /// </summary>
        /// <param name="guid">The guid to convert to string.</param>
        /// <returns>A string representation of the guid.</returns>
        public static string ToShortString(this Guid guid)
        {
            var converter = new ShortGuidConverter();
            return converter.ConvertToString(guid);
        }
    }
}
